﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BPM.Foundation.PWDB;
namespace BPM.Foundation.PWService
{
    public partial interface IPowerService
    {
        //--测试用wxwinter 20080710 创建
        [System.ServiceModel.OperationContract]
        List<PW_DepartmentDutyUserRelation_V> ddu(string userNo, string dutyNo, string departmentNo);

        //--测试用wxwinter 20080710 创建
        [System.ServiceModel.OperationContract]
        List<PW_DutyInDepartment_V> dd(string dutyNo, string depart);
    }

    public partial class PowerService : IPowerService
    {

        //[6.1	得到部门职能关系视图]
        public List<PW_DutyInDepartment_V> getDutyInDepartmentView(string pid)
        {
            return PWDB.PW_DutyInDepartment_V.ToList();
        }
        //-

        //[6.2	得到部门职能关系中文视图]
        public List<PW_DutyInDepartment_VCN> getDutyInDepartmentViewCN(string pid)
        {
            return PWDB.PW_DutyInDepartment_VCN.ToList(); ;
        }
        //-

        //[6.3	得到部门职能人员关系视图]
        public List<PW_DepartmentDutyUserRelation_V> getDepartmentDutyUserRelationView(string pid)
        {
            return PWDB.PW_DepartmentDutyUserRelation_V.ToList(); ;
        }
        //-

        //[6.4	得到部门职能人员关系中文视图]
        public List<PW_DepartmentDutyUserRelation_VCN> getDepartmentDutyUserRelationViewCN(string pid)
        {
            return PWDB.PW_DepartmentDutyUserRelation_VCN.ToList(); ;
        }
        //-

        //[6.5	人员信息全搜索]
        public List<PW_User> searchAllUser(string pid, string condition)
        {
            //[1]
            if (string.IsNullOrEmpty(condition))
            {
                return null;
            }

            //[2]
            try
            {
                return PWDB.searchAllUser(condition).ToList();
            }
            catch
            {
                return null;
            }
        }
        //-

        //[6.6 -测试用wxwinter 20080710  创建]
        public List<PW_DutyInDepartment_V> dd(string dutyNo, string departmentNo)
        {
            
            //全空
           if(string.IsNullOrEmpty(dutyNo) && string.IsNullOrEmpty(departmentNo))
           {
               return PWDB.PW_DutyInDepartment_V.ToList();
           }
           //全不空
            if(!string.IsNullOrEmpty(dutyNo) && !string.IsNullOrEmpty(departmentNo))
           {
               var v = PWDB.PW_DutyInDepartment_V.Where(p => p.departmentNo == departmentNo && p.dutyNo == dutyNo).ToList();
               return v;
           }
            //dutyNo不空,departmentNo空
            if (!string.IsNullOrEmpty(dutyNo) && string.IsNullOrEmpty(departmentNo))
            {
                var v = PWDB.PW_DutyInDepartment_V.Where(p =>  p.dutyNo == dutyNo).ToList();
                return v;
            }
            //dutyNo空,departmentNo不空
            if (string.IsNullOrEmpty(dutyNo) && !string.IsNullOrEmpty(departmentNo))
            {
                var v = PWDB.PW_DutyInDepartment_V.Where(p => p.departmentNo == departmentNo).ToList();
                return v;
            }

            return PWDB.PW_DutyInDepartment_V.ToList();
        }
        //-

        //[6.7 -测试用wxwinter 20080710 创建]
        public List<PW_DepartmentDutyUserRelation_V> ddu(string userNo, string dutyNo, string departmentNo)
        {
            //全空
            if (string.IsNullOrEmpty(dutyNo) && string.IsNullOrEmpty(departmentNo) && string.IsNullOrEmpty(userNo))
            {
                return PWDB.PW_DepartmentDutyUserRelation_V.ToList();
            }

            //全不空
            if (!string.IsNullOrEmpty(dutyNo) && !string.IsNullOrEmpty(departmentNo) && !string.IsNullOrEmpty(userNo))
            {
                return PWDB.PW_DepartmentDutyUserRelation_V.Where(p => p.departmentNo == departmentNo && p.dutyNo == dutyNo && p.userNo == userNo).ToList();
            }

            //departmentNo,dutyNo不空
            if (!string.IsNullOrEmpty(dutyNo) && !string.IsNullOrEmpty(departmentNo))
            {
                var v = PWDB.PW_DepartmentDutyUserRelation_V.Where(p => p.departmentNo == departmentNo && p.dutyNo == dutyNo).ToList();
                return v;
            }


            //departmentNo不空
            if (!string.IsNullOrEmpty(departmentNo))
            {
                return PWDB.PW_DepartmentDutyUserRelation_V.Where(p => p.departmentNo == departmentNo).ToList();
            }


            //userNo不空
            if (!string.IsNullOrEmpty(userNo))
            {
                return PWDB.PW_DepartmentDutyUserRelation_V.Where(p => p.userNo == userNo).ToList();
            }

            //dutyNo不空
            if (!string.IsNullOrEmpty(dutyNo))
            {
                return PWDB.PW_DepartmentDutyUserRelation_V.Where(p => p.dutyNo == dutyNo).ToList();
            }

            return PWDB.PW_DepartmentDutyUserRelation_V.ToList(); ;
        }
        //-

    }
}